commonlibsse_ng\re\b\BSTHashMap/
hasher.rs

1use crate::re::CRC::Crc32Hasher;
2use core::marker::PhantomData;
3
4#[derive(Debug, Clone, Copy, Default)]
5pub struct BSTScatterKeyExtractor<K, V> {
6    marker: PhantomData<(K, V)>,
7}
8
9pub trait KeyStrategy {
10    type Key;
11    type Value;
12    /// Key value pair(or Single)
13    type Pair;
14
15    /// e.g. Gets first tuple(Value) element from tuple
16    fn get_key(value: &Self::Pair) -> &Self::Key;
17
18    fn hash(key: &Self::Key) -> u32;
19}
20
21impl<K, V> KeyStrategy for BSTScatterKeyExtractor<K, V>
22where
23    K: core::hash::Hash,
24{
25    type Key = K;
26
27    type Value = V;
28
29    type Pair = (K, V);
30
31    #[inline]
32    fn get_key(value: &Self::Pair) -> &Self::Key {
33        &value.0
34    }
35
36    #[inline]
37    fn hash(key: &Self::Key) -> u32 {
38        use core::hash::{BuildHasher as _, BuildHasherDefault};
39
40        type Crc32Hash = BuildHasherDefault<Crc32Hasher>;
41
42        Crc32Hash::new().hash_one(key) as u32
43    }
44}